<?php

namespace App\Models\templates;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\templates\ShippingTemplate
 *
 * @property int $id 编号
 * @property string $name 模板名称
 * @property int $type 计费方式  1 =>按件数  2=>按重量  3=>按体积
 * @property int $appoint 指定包邮  1开启0关闭
 * @property int $sort 排序
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read mixed $region_tables
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate whereAppoint($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\templates\ShippingTemplate whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class ShippingTemplate extends Model
{

    protected $table = 'shipping_templates';

    protected $fillable = [
        'name',
        'type',
        'appoint',
        'sort',
    ];

    public function regions()
    {

    }

    public function getRegionTablesAttribute($value)
    {
        $empty[] = [
            'id' => 0,
            'province_id' => 130000,
            'shipping_template_id' => 0,
            'city_id' => 0,
            'first' => 0,
            'first_price' => 0,
            'continue' => 0,
            'continue_price'
        ] ;

        return array_values(json_decode($value, true) ?: $empty);
    }

}
